<!--
 * @Author: lwHao
 * @Date: 2020-10-27 19:37:21
 * @LastEditors: lwHao
 * @LastEditTime: 2020-10-28 20:20:01
-->
<template>
  <Layout>
    <!-- Page Header -->
    <header class="masthead" :style="{
      backgroundImage: $page.post.cover ? `url(http://localhost:1337${$page.post.cover})` : `url('img/post-bg.jpg')`
    }">
      <div class="overlay"></div>
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-md-10 mx-auto">
            <div class="post-heading">
              <h1>{{$page.post.title}}</h1>
              <!-- <h2 class="subheading">Problems look mighty small from 150 miles up</h2> -->
              <span class="meta">
                Posted by
                <a href="#">{{$page.post.author.firstname}}{{$page.post.author.lastname}}</a>
                on {{$page.post.created_at}}
              </span>
            </div>
          </div>
        </div>
      </div>
    </header>

    <!-- Post Content -->
    <article>
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-md-10 mx-auto" v-html="mdToHtml($page.post.content)">
          </div>
        </div>
      </div>
    </article>
  </Layout>
</template>

<page-query>
query ($id: ID!) {
  post: strapiPost(id: $id) {
    id
    title
    content
    published_at
    created_at
    updated_at
    is_publish
    author {
      firstname
      lastname
    }
    tags {
      title
    }
    path
  }
}
</page-query>
<script>
import markdownIt from 'markdown-it'
const md = new markdownIt()
export default {
  name: 'PostPage',
  methods: {
    mdToHtml(content){
      return md.render(content)
    }
  }
}
</script>

<style>
</style>